package com.example.demo.entity.response.repository;

import com.example.demo.common.entity.response.BaseResponse;
import com.example.demo.entity.pojo.repository.MaterialPoJo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import org.springframework.beans.BeanUtils;

import java.util.Objects;

/**
 * 材料响应对象.
 *
 * @author Mei Ruoxiao
 * @since 2020/9/17
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@ApiModel("材料响应对象")
public class MaterialResponse extends BaseResponse {
    @ApiModelProperty(value = "名称")
    private String name;

    @ApiModelProperty(value = "规格/型号", example = "HD20200915S")
    private String spec;

    @ApiModelProperty(value = "材料编码", example = "HDAS5263")
    private String code;

    @ApiModelProperty(value = "库存", example = "25412")
    private Integer stock;

    @ApiModelProperty(value = "废品(件)", example = "412")
    private Integer garbage;

    @ApiModelProperty(value = "所属仓库ID", example = "182933571428352")
    private Long repositoryId;

    @ApiModelProperty(value = "材料类型 0-材料 1-成品 2-废品", example = "0")
    private int type;


    public static MaterialResponse of(final MaterialPoJo poJo) {
        MaterialResponse response = new MaterialResponse();
        if (Objects.isNull(poJo)) {
            return response;
        }
        // 将 Domain 对象转换成 Response 对象
        BeanUtils.copyProperties(poJo, response);
        return response;
    }
}
